package com.gongj.apppay.controller;

import com.gongj.apppay.dto.PayDTO;
import com.gongj.apppay.rabbitmq.producer.RabbitSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/api/pay")
public class PayController {

    @Autowired
    @Qualifier("restTemplateBean")
    RestTemplate restTemplate;

    @Autowired
    RabbitSender rabbitSender;
    @GetMapping
    public String getUser(){
        String result = restTemplate.getForObject("http://appUser/api/user", String.class);
        return result;
    }

    @GetMapping("/sendPay")
    public String sendPay(){
        for (int i = 0; i < 10; i++) {
            PayDTO payDTO = new PayDTO();
            payDTO.setMoney("8888888");
            payDTO.setPayBank("***银行");
            payDTO.setPayId(123541880889922L);
            payDTO.setPayTime("2029-11-18 14:15:48 654");
            rabbitSender.send(payDTO);
        }
        return "success";
    }

    @GetMapping("/getPayInfo")
    public String getPayInfo(String name){
        return "PAY调用成功：" + name;
    }
}
